package com.pj.wisdomlogistics.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.cons.Cons;
import com.pj.wisdomlogistics.entity.TakeoutMenuInfo;
import com.pj.wisdomlogistics.ui.view.CountView;
import com.pj.wisdomlogistics.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by HelloWorld on 2017/9/12.
 */

public class TakeOutDelicatessenAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private Context mContext;
    private List<TakeoutMenuInfo.ShushiBean> mList;

    public TakeOutDelicatessenAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setData(List<TakeoutMenuInfo.ShushiBean> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent, R.layout.item_takeout_menu);
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, final int position) {
        AutoUtils.autoSize(holder.itemView);
        holder.getTextView(R.id.tv_dishes_name).setText(mList.get(position).getFoodName());

        if(position % 2 != 0){
            holder.getView(R.id.ll_layout).setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }

        CountView mCountView = holder.getView(R.id.v_count);

        mCountView.setListener(new CountView.countListener() {
            @Override
            public void countChange(int currentCount) {
                mCountListener.itemClick(
                        mList.get(position).getFoodID(),
                        currentCount,
                        mList.get(position).getFoodName(),
                        mList.get(position).getFoodPrice(),
                        mList.get(position).getFoodUnit(),
                        Cons.TakeoutMeal.DELICATESSEN);
            }
        }, false);
        mCountView.setMaxCount(mList.get(position).getMaxCount());
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public countListener mCountListener;

    public interface countListener {
        public void itemClick(int id, int currentCount, String name, double price, String unit, int type);
    }

    public void setListener(countListener mListener) {
        this.mCountListener = mListener;
    }

}
